package com.situ.day2;

import org.junit.Test;

import java.util.Scanner;

public class HomeWork {
//    1、计算某年是不是闰年：
//    能被4整除，但是不能被100整除    ||   能被400整除
    @Test
    public void test1() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年份：");
        int year = scanner.nextInt();
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            System.out.println(year + "是闰年");
        } else {
            System.out.println(year + "不是闰年");
        }
    }

    //3、计算1-100以内所有奇数的和以及所有偶数的和，分别打印出来
    @Test
    public void test2() {
        int oddSum = 0;
        int evenSum = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                evenSum += i;
            } else {
                oddSum += i;
            }
        }
        System.out.println("oddSum: " + oddSum);
        System.out.println("evenSum: " + evenSum);
    }

//    1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//    求出上面数组中0-9分别出现的次数
    @Test
    public void test33() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int count0 = 0;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        int count4 = 0;
        int count5 = 0;
        for (int i = 0; i < scores.length; i++) {
            switch (scores[i]) {
                case 0:
                    count0++;
                    break;
                case 1:
                    count1++;
                    break;
                case 2:
                    count2++;
                    break;
            }
           /* if (scores[i] == 0) {
                count0++;
            } else if (scores[i] == 1) {
                count1++;
            } else if (scores[i] == 2) {
                count2++;
            }*/
        }
        System.out.println("count0: " + count0);
        System.out.println("count1: " + count1);
    }

    @Test
    public void test36() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        //0-9这10个位置正好放0-9这10个数出现的位置
        int[] array = new int[10];
        for (int i = 0; i < scores.length; i++) {
            switch (scores[i]) {
                case 0:
                    array[0]++;
                    break;
                case 1:
                    array[1]++;
                    break;
                case 2:
                    array[2]++;
                    break;
            }
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println("count" + i + ": " + array[i]);
        }
    }

    @Test
    public void test361() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        //0-9这10个位置正好放0-9这10个数出现的位置
        int[] array = new int[10];
        for (int i = 0; i < scores.length; i++) {
            switch (scores[i]) {
                case 0:
                    array[0]++;
                    break;
                case 1:
                    array[1]++;
                    break;
                case 2:
                    array[2]++;
                    break;
            }
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println("count" + i + ": " + array[i]);
        }
    }

    @Test
    public void test362() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        //0-9这10个位置正好放0-9这10个数出现的位置
        int[] array = new int[10];
        for (int i = 0; i < scores.length; i++) {
            array[scores[i]]++;
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println("count" + i + ": " + array[i]);
        }
    }

//    2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//    要求求出其中的奇数个数和偶数个数。
    @Test
    public void test44() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int oddCount = 0;
        int evenCount = 0;
        for (int score : scores) {
            if (score % 2 == 0) {
                evenCount++;
            } else {
                oddCount++;
            }
        }
    }

    @Test
    public void test889() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串： ");
        String str = scanner.next();
        //String str = "abcba";
        char[] array = str.toCharArray();
        //初始认为是回文
        boolean isHuiWen = true;
        for (int i = 0; i < array.length / 2; i++) {
            if (array[i] != array[array.length - i - 1]) {
                isHuiWen = false;
                break;
            }
        }

        if (isHuiWen) {
            System.out.println("是回文");
        } else {
            System.out.println("不是回文");
        }

    }



}
